/*
 * 1352. Compare Version Numbers
 * Compare two version numbers version1 and version2.
 * If version1 > version2 return 1, if version1 < version2 return -1, otherwise return 0.
 * 
 * You may assume that the version strings are non-empty and contain only digits and the . character.
 * The . character does not represent a decimal point and is used to separate number sequences.
 * For instance, 2.5 is not "two and a half" or "half way to version three", it is the fifth second-level revision of the second first-level revision.
 * https://www.lintcode.com/problem/compare-version-numbers/description
 * 
 * 样例
 * Here is an example of version numbers ordering:
 * 0.1 < 1.1 < 1.2 < 13.37
 * 
 * 2018.06.14 @jeyming
 */
package compare_version_numbers_1352;

public class Compare_version_numbers_1352 {
	/**
	 * @param version1: the first given number
	 * @param version2: the second given number
	 * @return: the result of comparing
	 */
	public static int compareVersion(String version1, String version2) {
		// Write your code here
		//    	double d1 = Double.parseDouble(version1);
		//    	double d2 = Double.parseDouble(version2);
		//    	if((d1 - d2) > 0) {
		//    		return 1;
		//    	} else if((d1 - d2) < 0) {
		//    		return -1;
		//    	} else {
		//    		return 0;
		//    	}
		boolean judge = true;
		int cnt1 = 0, cnt2 = 0;
		while(judge) {
			int tmp1 = 0;
			int tmp2 = 0;
			for(int i = cnt1; i < version1.length(); ++i) {
				if(version1.charAt(i) == '.') {
					cnt1 = i + 1;
					break;
				} 
				tmp1 += version1.charAt(i) - '0';
				if(i == (version1.length() - 1))
					cnt1 = i + 1;
			}
			for(int i = cnt2; i < version2.length(); ++i) {
				if(version2.charAt(i) == '.') {
					cnt2 = i + 1;
					break;
				}
				tmp2 += version2.charAt(i) - '0';
				if(i == (version2.length() - 1))
					cnt2 = i + 1;
			}
			if((tmp1 - tmp2) > 0) {
				return 1;
			} else if((tmp1 -tmp2) < 0){
				return -1;
			} 
			if(cnt1 == version1.length() && cnt2 == version2.length())
				break;
		}
		return 0;
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		//"7.5.2.4"
		//"7.5.3"
		//System.out.println(compareVersion("0.1","1.1"));
		//System.out.println(compareVersion("7.5.2.4","7.5.3"));
		System.out.println(compareVersion("1","01"));

	}

}
